package academic.emailClient.control.listeners;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;

import javax.swing.JPanel; 

import academic.emailClient.control.MessageMapper;
import academic.emailClient.model.EmailClientModel;
import academic.emailClient.model.entities.Message;
import academic.emailClient.view.EmailClientViewInterface;
import academic.emailClient.view.entities.MessageView;



	/**
	 * Add a mouse listener to show a right click mouse pop up
	 * 
	 */
    public class GetMessageListListener implements MouseListener{
    	
    	private EmailClientModel model;
    	private EmailClientViewInterface view;
    	private static int DOUBLE_CLICK = 2;
    	
    	/**
    	 * Constructor
    	 * @param view
    	 * @param model
    	 */
    	public GetMessageListListener(EmailClientViewInterface view, EmailClientModel model){
    		this.view = view;
    		this.model = model;
    	}
    	
        
    /**
     *  received handlers events Implementation 
     */
	@Override
	public void mouseClicked(MouseEvent e) {	
		if (e.getClickCount() < DOUBLE_CLICK)
			return;
		
		/**
		 * Get Folder Path
		 */
		try {
			String folderPath = view.getSelectedFolderPath();
			ArrayList<Message> messages = model.getFolderContent(folderPath);
			ArrayList<MessageView> messagesView =  MessageMapper.mapToMessageViewList(messages);
			view.updateMailBoxList(messagesView);
		}
		catch (Exception ex){
			ex.printStackTrace();
		}
	}

	@Override
	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mousePressed(MouseEvent e) {
		//Validates if folder was selected using double click
		
		//view.createInboxPanel(messagesView);
	}

	@Override
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub

	}
	
	public class InboxTreeControllerListener implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent arg0) {
			// TODO Auto-generated method stub
			view.updateInboxList(new JPanel());
			
		}
	}
  }
